package cn.jiyun.controller;

import cn.jiyun.page.PageResult;
import cn.jiyun.page.QueryPageBean;
import cn.jiyun.pojo.Project;
import cn.jiyun.service.ProjectService;
import cn.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("project")
public class ProjectController {
    @Autowired
    private ProjectService projectService;

    @RequestMapping("add")
    public Result add(@RequestBody Project project){
        int add = projectService.add(project);
        if (add>0){
            return new Result(true,"success");
        }else {
            return new Result(false,"file");
        }
    }

    @RequestMapping("update")
    public Result update(@RequestBody Project project){
        int add = projectService.update(project);
        if (add>0){
            return new Result(true,"success");
        }else {
            return new Result(false,"file");
        }
    }
    @RequestMapping("findAll")
    public PageResult findAll(@RequestBody QueryPageBean queryPageBean){
     return projectService.findAll(queryPageBean);
    }

    @RequestMapping("delete")
    public Result delete(Integer pid){
        int add = projectService.delete(pid);
        if (add>0){
            return new Result(true,"success");
        }else {
            return new Result(false,"file");
        }
    }

    @RequestMapping("findById")
    public Result findById(Integer pid){
        Project byId = projectService.findById(pid);
        return new Result(true,"成功",byId);
    }

    @RequestMapping("findName")
    public Result findName(){
        List<Project> byId = projectService.findName();
        return new Result(true,"成功",byId);
    }

}
